package pl.edu.agh.iosr.gamblingzone.dao.hibernate;

import java.util.List;
import java.util.Random;

import pl.edu.agh.iosr.gamblingzone.dao.QuoteDAO;
import pl.edu.agh.iosr.gamblingzone.model.Quote;

/**
 * The Class QuoteDAOBean.
 */
public class QuoteDAOBean extends GenericDAOBean<Quote, Long> 
		implements QuoteDAO {

	/* (non-Javadoc)
	 * @see pl.edu.agh.iosr.gamblingzone.dao.QuoteDAO#getRandomQuote()
	 */
	public Quote getRandomQuote() {
		// create random generator
		Random random = new Random();
		int allQuotes = getEntitiesCount();
		
		// get random quote
		int randQuote = Math.abs(random.nextInt(allQuotes));
		setPageSize(1);
		List<Quote> resList = findAll(randQuote);
		
		if (resList == null || resList.size() <= 0) {
			return new Quote();
		}
		
		return resList.get(0);
	}
	
}